home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / extend.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  137 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *        Extended (M-X) commands.
  4.  * Version:    29
  5.  * Last edit:    14-Feb-86
  6.  * By:        rex::conroy
  7.  *        decvax!decwrl!dec-rhea!dec-rex!conroy
  8.  */
  9. #include    "def.h"
  10.  
  11. /*
  12.  * This function modifies the keyboard
  13.  * binding table, by adjusting the entries in the
  14.  * big "bindings" array. Most of the grief deals with the
  15.  * prompting for additional arguments. This code does not
  16.  * work right if there is a keyboard macro floating around.
  17.  * Should be fixed.
  18.  */
  19. bindtokey(f, n, k)
  20. {
  21.     register int    s;
  22.     register SYMBOL    *sp;
  23.     register int    c;
  24.     char        xname[NXNAME];
  25.  
  26.     if (kbdmip!=NULL || kbdmop!=NULL) {
  27.         eprintf("Not now");
  28.         return (FALSE);
  29.     }
  30.     if ((s=eread("Function: ", xname, NXNAME, EFAUTO, NULL)) != TRUE)
  31.         return (s);
  32.     if ((sp=symlookup(xname)) == NULL) {
  33.         eprintf("Unknown function for binding");
  34.         return (FALSE);
  35.     }
  36.     eputc(' ');
  37.     eputc('K');
  38.     eputc('e');
  39.     eputc('y');
  40.     eputc(':');
  41.     eputc(' ');
  42.     ttflush();
  43.     c = getkey();                /* Read key.        */
  44.     keyname(xname, c);            /* Display keyname.    */
  45.     eputs(xname);
  46.     ttflush();
  47.     if (binding[c] != NULL)            /* Unbind old, and    */
  48.         --binding[c]->s_nkey;
  49.     binding[c] = sp;            /* rebind new.        */
  50.     ++sp->s_nkey;
  51.     return (TRUE);
  52. }
  53.  
  54. /*
  55.  * Extended command. Call the message line
  56.  * routine to read in the command name and apply autocompletion
  57.  * to it. When it comes back, look the name up in the symbol table
  58.  * and run the command if it is found and has the right type.
  59.  * Print an error if there is anything wrong.
  60.  */
  61. extend(f, n, k)
  62. {
  63.     register SYMBOL    *sp;
  64.     register int    s;
  65.     char        xname[NXNAME];
  66.  
  67.     if ((s=eread(": ", xname, NXNAME, EFNEW|EFAUTO, NULL)) != TRUE)
  68.         return (s);
  69.     if ((sp=symlookup(xname)) != NULL)
  70.         return ((*sp->s_funcp)(f, n, KRANDOM));
  71.     eprintf("Unknown extended command");
  72.     return (ABORT);
  73. }
  74.  
  75. /*
  76.  * Read a key from the keyboard, and look it
  77.  * up in the binding table. Display the name of the function
  78.  * currently bound to the key. Say that the key is not bound
  79.  * if it is indeed not bound, or if the type is not a
  80.  * "builtin". This is a bit of overkill, because this is the
  81.  * only kind of function there is.
  82.  */
  83. help(f, n, k)
  84. {
  85.     register SYMBOL    *sp;
  86.     register int    c;
  87.     char        b[20];
  88.  
  89.     c = getkey();
  90.     keyname(b, c);
  91.     if ((sp=binding[c]) == NULL)
  92.         eprintf("[%s is unbound]", b);
  93.     else
  94.         eprintf("[%s is bound to %s]", b, sp->s_name);
  95.     return (TRUE);
  96. }
  97.  
  98. /*
  99.  * This function creates a table, listing all
  100.  * of the command keys and their current bindings, and stores
  101.  * the table in the standard pop-op buffer (the one used by the
  102.  * directory list command, the buffer list command, etc.). This
  103.  * lets MicroEMACS produce it's own wall chart. The bindings to
  104.  * "ins-self" are only displayed if there is an argument.
  105.  */
  106. wallchart(f, n, k)
  107. {
  108.     register int    s;
  109.     register int    key;
  110.     register SYMBOL    *sp;
  111.     register char    *cp1;
  112.     register char    *cp2;
  113.     char        buf[64];
  114.  
  115.     if ((s=bclear(blistp)) != TRUE)        /* Clear it out.    */
  116.         return (s);
  117.     (void) strcpy(blistp->b_fname, "");
  118.     for (key=0; key<NKEYS; ++key) {        /* For all keys.    */
  119.         sp = binding[key];
  120.         if (sp != NULL
  121.         && (f!=FALSE || strcmp(sp->s_name, "ins-self")!=0)) {
  122.             keyname(buf, key);
  123.             cp1 = &buf[0];        /* Find end.        */
  124.             while (*cp1 != 0)
  125.                 ++cp1;
  126.             while (cp1 < &buf[16])    /* Goto column 16.    */
  127.                 *cp1++ = ' ';                
  128.             cp2 = sp->s_name;    /* Add function name.    */
  129.             while (*cp1++ = *cp2++)
  130.                 ;
  131.             if (addline(buf) == FALSE)
  132.                 return (FALSE);
  133.         }
  134.     }
  135.     return (popblist());
  136. }
  137.